<%--
  Created by IntelliJ IDEA.
  User: wangxiaotong
  Date: 2022/2/11
  Time: 11:19
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<div id="page_nav">
    <c:if test="${requestScope.page.pageNo > 1}">
        <a href="${requestScope.page.url}&pageNo=1">首页</a>
        <a href="${requestScope.page.url}&pageNo=${requestScope.page.pageNo - 1}">上一页</a>
    </c:if>
    <c:choose>
        <c:when test="${requestScope.page.pageTotal <= 5}">
            <c:forEach begin="1" end="${requestScope.page.pageNo}" var="i">
                <c:if test="${i == requestScope.page.pageNo}">
                    【${requestScope.page.pageNo}】
                </c:if>
                <c:if test="${i != requestScope.page.pageNo}">
                    <a href="${requestScope.page.url}&pageNo=${i}">${i}</a>
                </c:if>
            </c:forEach>
        </c:when>
        <c:when test="${requestScope.page.pageTotal > 5}">
            <c:choose>
                <c:when test="${requestScope.page.pageNo >= 1 && requestScope.page.pageNo < 4}">
                    <c:forEach begin="1" end="${requestScope.page.pageNo}" var="i">
                        <c:if test="${i == requestScope.page.pageNo}">
                            【${requestScope.page.pageNo}】
                        </c:if>
                        <c:if test="${i != requestScope.page.pageNo}">
                            <a href="${requestScope.page.url}&pageNo=${i}">${i}</a>
                        </c:if>
                    </c:forEach>
                </c:when>
                <c:when test="${requestScope.page.pageNo > requestScope.page.pageTotal - 3}">
                    <c:forEach begin="${requestScope.page.pageNo}" end="${requestScope.page.pageTotal}" var="i">
                        <c:if test="${i == requestScope.page.pageNo}">
                            【${requestScope.page.pageNo}】
                        </c:if>
                        <c:if test="${i != requestScope.page.pageNo}">
                            <a href="${requestScope.page.url}&pageNo=${i}">${i}</a>
                        </c:if>
                    </c:forEach>
                </c:when>
                <c:when test="${requestScope.page.pageNo >= 4 && requestScope.page.pageNo < requestScope.page.pageTotal - 2}">
                    <c:forEach begin="${requestScope.page.pageNo - 2}" end="${requestScope.page.pageNo + 2}" var="i">
                        <c:if test="${i == requestScope.page.pageNo}">
                            【${requestScope.page.pageNo}】
                        </c:if>
                        <c:if test="${i != requestScope.page.pageNo}">
                            <a href="${requestScope.page.url}&pageNo=${i}">${i}</a>
                        </c:if>
                    </c:forEach>
                </c:when>
            </c:choose>
        </c:when>
    </c:choose>
    <c:if test="${requestScope.page.pageNo < requestScope.page.pageTotal}">
        <a href="${requestScope.page.url}&pageNo=${requestScope.page.pageNo + 1}">下一页</a>
        <a href="${requestScope.page.url}&pageNo=${requestScope.page.pageTotal}">末页</a>
    </c:if>
    共${requestScope.page.pageTotal}页，${requestScope.page.pageCount}条记录
    到第<input value="${param.pageNo}" name="pn" id="pn_input"/>页
    <input id="searchPageBtn" type="button" value="确定">
    <script type="text/javascript">
        $(function () {
           $("#searchPageBtn").click(function () {
             var pageNo = $("#pn_input").val();
             if(pageNo < 1) {
                 alert("您输入的页码不存在,自动为您跳转到首页");
                 pageNo = 1;
             }
             if(pageNo > ${requestScope.page.pageTotal}) {
                 alert("您输入的页码超过最大页码，自动为您跳转到末页");
                 pageNo = ${requestScope.page.pageTotal};
             }
             location.href = "${pageScope.basePath}${requestScope.page.url}&pageNo=" + pageNo;
           });
        });
    </script>
</div>
